home *** CD-ROM | disk | FTP | other *** search
/ Internet Surfer 2.0 / Internet Surfer 2.0 (Wayzata Technology) (1996).iso / pc / textfile / faqs / emacs_fa / part4 < prev    next >
Encoding:
Internet Message Format  |  1992-12-26  |  44.8 KB

  1. Xref: bloom-picayune.mit.edu gnu.emacs.help:7402 comp.emacs:15251 news.answers:3116
  2. Path: bloom-picayune.mit.edu!enterpoop.mit.edu!snorkelwacker.mit.edu!eff!sol.ctr.columbia.edu!spool.mu.edu!hri.com!noc.near.net!news.bbn.com!bu.edu!bigbird!jbw
  3. From: jbw@bigbird.bu.edu (Joe Wells)
  4. Newsgroups: gnu.emacs.help,comp.emacs,news.answers
  5. Subject: GNU Emacs FAQ (4/5, 125-151): Keybindings/Output
  6. Summary: READ BEFORE POSTING.  A regularly posted list of answers to frequently
  7.          asked questions (FAQs) about GNU Emacs and many Emacs Lisp programs.
  8.          Contains pointers to other resources.  Follow "References:" link for
  9.          more metainfo.
  10. Keywords: gnu emacs faq answers frequently asked questions periodic
  11. Message-ID: <GNU-Emacs-FAQ-4.1992.09.22.011020@bigbird.bu.edu>
  12. Date: 22 Sep 92 01:10:20 GMT
  13. Expires: 21 Nov 92 01:10:20 GMT
  14. References: <GNU-Emacs-FAQ-0.1992.09.22.011020@bigbird.bu.edu>
  15. Sender: news@bu.edu
  16. Reply-To: gnu-emacs-faq-maintainers@bigbird.bu.edu
  17. Followup-To: poster
  18. Organization: GNU's Not UNIX
  19. Lines: 975
  20. Approved: news-answers-request@mit.edu
  21. Supersedes: <GNU-Emacs-FAQ-4.1992.06.28.234430@bigbird.bu.edu>
  22.  
  23. Archive-Name: GNU-Emacs-FAQ/part4
  24. Last-Modified: Mon, 21 Sep 1992 03:20:49 GMT
  25. Last-Posted: Tue, 22 Sep 1992 01:10:20 GMT
  26.  
  27.                     GNU Emacs FAQ: Keybindings/Output
  28.  
  29. If you are viewing this text in a GNU Emacs Buffer, you can type "M-2 C-x $" to
  30. get an overview of just the questions.  Then, when you want to look at the text
  31. of the answers, just type "C-x $".
  32.  
  33. To search for a question numbered XXX, type "M-C-s ^XXX:", followed by a C-r if
  34. that doesn't work, then type ESC to end the search.
  35.  
  36. A `+' in the 78th column means something was inserted on the line.  A `-' means
  37. something was deleted and a `!' means some combination of insertions and
  38. deletions occurred.
  39.  
  40. Full instructions for getting the latest FAQ are in question 22.  Also see the
  41. `Introduction to news.answers' posting in the `news.answers' newsgroup, or send
  42. e-mail to `mail-server@rtfm.mit.edu' with `help' on a body line, or use FTP,
  43. WAIS, or Prospero to rtfm.mit.edu.
  44.  
  45.  
  46.  
  47. Changing Key Bindings and Handling Key Binding Problems
  48.  
  49. 125: How do I bind keys (including function keys) to commands?
  50.   
  51.   1. Find out what character sequence is generated by the keystroke sequence
  52.      you wish to bind to a command.  See question 129 for how to do this.
  53.      Keep in mind that the character sequences generated by a keystroke
  54.      sequence varies from one terminal to another.  You may also get
  55.      different results depending on what type of machine you are running on
  56.      (see question 128).  For example, these keystrokes may generate these
  57.      character sequences:
  58.   
  59.        F1        ---> ESC [ 2 2 4 z
  60.        Shift-R10 ---> ESC O t
  61.        L7        ---> ESC [ 3 1 ~
  62.        Remove    ---> C-@
  63.   
  64.   2. Figure out what the Emacs Lisp syntax is for this character sequence.
  65.      Inside an Emacs Lisp string, RET, LFD, DEL, ESC, SPC, and TAB are
  66.      specified with `\r', `\n', `\C-?', `\e', ` ', and `\t'.  C-x is
  67.      specified by `\C-x'.  M-x is specified the same was as "ESC x".
  68.      (Control characters may also be specified as themselves, but I don't
  69.      recommend it.)  An Emacs Lisp string begins and ends with the double
  70.      quote character, `"'.  Here are some examples:
  71.   
  72.        ESC [ D       ---> "\e[D"
  73.        ESC [ 2 2 7 z ---> "\e[227z"
  74.        ESC [ 1 8 ~   ---> "\e[18~"
  75.        C-M-r         ---> "\e\C-r"
  76.   
  77.   3. If some prefix of the character sequence is already bound, you must
  78.      unbind it by binding it to `nil'.  For example:
  79.   
  80.        (global-set-key "\e[" nil)
  81.   
  82.   4. Pick a command to bind your key sequence to.  A command can be a
  83.      "symbol" with a function definition, or a "lambda list", or a string
  84.      (which is treated as a macro).  For example:
  85.   
  86.        (global-set-key "\e[D" 'backward-char)
  87.        (global-set-key "\e[227~" "\exgoto-line\r") ; macro
  88.   
  89.   See `Key Bindings' and `Rebinding' in the online manual.
  90.   
  91.   In Emacs 19 (including Lucid Emacs), you can bind function key F24 like    +
  92.   this:                                                                      +
  93.                                                                              +
  94.     (global-set-key 'f24 'some-command)                                      +
  95.   
  96. 126: Why does Emacs say `Key sequence XXX uses invalid prefix characters'?
  97.   
  98.   A prefix of the character sequence you were trying to bind was already
  99.   bound.  Usually, the sequence is "ESC [", in which case you should
  100.   evaluate this form first:
  101.   
  102.     (define-key esc-map "[" nil)
  103.   
  104.   NOTE: By default, "ESC [" is bound to backward-paragraph, and if you do
  105.   this you will lose this key binding.  For most people, this is not a
  106.   problem.
  107.   
  108.   See question 125.
  109.   
  110. 127: Why doesn't this [terminal or window-system setup] code work in my
  111.  .emacs file, but it works just fine after Emacs starts up?
  112.   
  113.   This is because you're trying to do something in your .emacs file that
  114.   needs to be postponed until after the terminal/window-system setup code
  115.   is loaded.  This is a result of the order in which things are done
  116.   during the startup of Emacs.  For more details see question 135.
  117.   
  118.   In order to postpone the execution of Emacs Lisp code until after the
  119.   terminal/window-system setup, set the value of the variable
  120.   term-setup-hook or window-setup-hook to be a function which does what
  121.   you want.
  122.   
  123.   See etc/OPTIONS for a complete explanation of what Emacs does every time
  124.   it is started.
  125.   
  126.   Here is a simple example of how to set term-setup-hook:
  127.   
  128.     (setq term-setup-hook
  129.       (function
  130.        (lambda ()
  131.          (cond ((string-match "\\`vt220" (or (getenv "TERM") ""))
  132.             ;; Make vt220's "Do" key behave like M-x:
  133.             (define-key CSI-map "29~" 'execute-extended-command))
  134.            ))))
  135.   
  136. 128: How do I use function keys under X Windows?
  137.   
  138.   This depends on whether you are running Emacs inside a terminal emulator
  139.   window, or whether you are allowing Emacs to create its own X window.
  140.   You can tell which you are doing by noticing whether Emacs creates a new
  141.   window when you start it.
  142.   
  143.   If you are running Emacs inside a terminal emulator window, then it
  144.   behaves exactly as it does on any other tty.  In this case, for function
  145.   keys to be useful, they must generate character sequences that are sent
  146.   to the programs running inside the window as input.  The `xterm' program
  147.   has two different sets of character sequences that it generates when
  148.   function keys are pressed, depending on the sunFunctionKeys X resource
  149.   and the -sf and +sf command line options.  (To find out what these key
  150.   sequences are, see question 129.)  In addition, with xterm,
  151.   you can override what key sequence a specific function key (or any other
  152.   key) will generate with the `translations' resource.  This, for example:
  153.   
  154.     XTerm.VT100.Translations: #override \
  155.       <KeyPress>F1: string(0x1b) string("[xyzzy")
  156.   
  157.   makes the function key F1 generate the character sequence "ESC [xyzzy".
  158.   
  159.   On the other hand, if Emacs is managing its own X window, the following
  160.   description applies.  Emacs receives `KeyPress' events from the X server
  161.   when a key is pressed while the keyboard focus is in its window.  The
  162.   KeyPress event contains an X "keysym" code, which is simply an arbitrary
  163.   number corresponding to the name of the keysym, and information on which
  164.   "modifiers" such as `control' and `shift' are active.  For example, the
  165.   `Tab' keysym is 0xff09.  (Generally, a key on the keyboard will generate a
  166.   keysym whose name is the same as the label on the key, ie. the `Tab' key
  167.   will normally generate the `Tab' keysym.  This can be changed with the
  168.   xmodmap program.)  Emacs recognizes all the keysyms that correspond to
  169.   standard ASCII characters and internally uses the ASCII character instead.
  170.   
  171.   (WARNING: I am about to describe a gross, disgusting hack to you, have
  172.   your barf bag ready.)
  173.   
  174.   When Emacs receives the X keysym of one of the arrow keys, it behaves
  175.   the same as if it had received a letter key with the control modifier
  176.   down as follows (this is hard-coded):
  177.   
  178.     Up    becomes C-p
  179.     Down  becomes C-n
  180.     Right becomes C-f
  181.     Left  becomes C-b
  182.   
  183.   The way Emacs treats other keysyms depends on what kind of machine it was
  184.   compiled on.  The type of the display machine is irrelevant!  Function
  185.   keys are mapped internally to escape sequences, while other keys are
  186.   completely ignored.
  187.   
  188.   1. If compiled on a Sun, Emacs recognizes these X keysyms that
  189.      are normally on a Sun keyboard:
  190.   
  191.        F1 through F9
  192.        L1 through L10 (same as F11 through F20)
  193.        R1 through R15 (same as F21 through F35)
  194.      (The keys labelled R8, R10, R12, and R14 usually are mapped to the
  195.       X keysyms Up, Left, Right, and Down.)
  196.        Break (the `Alternate' key is given this keysym)
  197.   
  198.      These keys work like Sun function keys.  When Emacs recieves the
  199.      keysym, it will internally use character sequences that look like "ESC
  200.      [ ### z", where ### is replaced by a number.  The character sequences
  201.      are identical to those generated by Sun's keyboard under SunView.  Any
  202.      function key not listed above generates "ESC [ - 1 z".
  203.   
  204.      In order to use these key sequences, they should be bound to commands
  205.      using the standard key binding methods, just as if Emacs were running
  206.      on a regular terminal.
  207.   
  208.      WARNING: F11 and L1 are the same keysym in X, as are F12 and L2, etc.
  209.      {Yes, this is stupid.  Complain to the X consortium.}
  210.   
  211.   2. If not compiled on a Sun, the function keys will appear to Emacs in a
  212.      way remarkably similar to the keys of a DEC LK201 keyboard (used on
  213.      some VT series terminals).  These X keysyms will be recognized:
  214.   
  215.        F1 through F20
  216.        Help (treated same as F15)
  217.        Menu (treated same as F16, is the LK201 `Do' key)
  218.        Find
  219.        Insert (LK201 `Insert Here' key)
  220.        Select
  221.        Prior (LK201 `Prev Screen' key *** ONLY IN 18.58 AND LATER ***)
  222.        Next (LK201 `Next Screen' key *** ONLY IN 18.58 AND LATER ***)
  223.   
  224.      And finally, the LK201 key labelled `Remove' (or `Delete') is often
  225.      mapped to the Delete keysym which generates the DEL character (C-?)
  226.      instead of the key sequence given by the LK201 `Remove' key.  It may
  227.      also be mapped to some other keysym, such as `_Remove', in which case
  228.      you can't use it from within Emacs at all.
  229.   
  230.      Each function key will be internally converted to a character sequence
  231.      that looks like "ESC [ ## ~", where ## is replaced by a number.  The
  232.      character sequences are identical to those generated by a LK201
  233.      keyboard.  Any function key not listed above generates "ESC [ - 1 ~".
  234.   
  235.   For the complete list of the numbers which are generated by the function
  236.   keys, look in the file src/x11term.c at the definitions of the function
  237.   stringFuncVal.
  238.   
  239.   If you are running Emacs on a Sun machine, even if your X display is
  240.   running on a non-Sun machine (eg., an X terminal), you get the setup
  241.   described above for Suns.  The determining factor is what type of
  242.   machine Emacs is running (was compiled) on, not what type of machine
  243.   your X display is on.
  244.   
  245.   If you have function keys not listed above on your keyboard, you can use
  246.   `xmodmap' to change their keysym assignments to get keys that Emacs will
  247.   recognize, but that may screw up other programs.
  248.   
  249.   X resources are not used by Emacs to affect the key sequences generated.
  250.   In particular, there are no X key "translations" for Emacs.
  251.   
  252.   If you have function keys not listed above and you don't want to use
  253.   xmodmap to change their names, you might want to make a modification to
  254.   your Emacs.  Johan Vromans <jv@mh.nl> has made available a patch for Emacs
  255.   that adds the x-rebind-key function of Epoch to Emacs 18.58.  This allows
  256.   another layer of key rebinding before Emacs even sees the keys, and in
  257.   this layer you can rebind all of the keys and modifier combinations as
  258.   well.
  259.   
  260.   Anonymous FTP:
  261.     /ftp.eu.net:gnu/emacs/FP-Xfun.Z                                          +
  262.     /ftp.urc.tue.nl:pub/tex/emacs/FP-Xfun                                    +
  263.   
  264.   Johan Vromans explains what this buys for you:
  265.   
  266.     After implementing this, all keyboard keys can be configured to send
  267.     user definable sequences, eg.,
  268.   
  269.       (x-rebind-key "KP_F1" 0 "\033OP")
  270.   
  271.     This will have the keypad key PF1 send the sequence "ESC O P", just like
  272.     an ordinary VT series terminal.
  273.   
  274. 129: How do I tell what characters my function or arrow keys emit?
  275.   
  276.   Use this function by Randal L. Schwartz <merlyn@iwarp.intel.com>:
  277.   
  278.     (defun see-chars ()
  279.       "Displays characters typed, terminated by a 3-second timeout."
  280.       (interactive)
  281.       (let ((chars "")
  282.         (inhibit-quit t))
  283.     (message "Enter characters, terminated by 3-second timeout.")
  284.     (while (not (sit-for 3))
  285.       (setq chars (concat chars (list (read-char)))
  286.         quit-flag nil))        ; quit-flag maybe set by C-g
  287.     (message "Characters entered: %s" (key-description chars))))
  288.   
  289.   Alternatively, use the "C-h l" view-lossage command, which will display
  290.   the last 100 characters Emacs has seen in its input stream.  Kevin
  291.   Gallagher <kgallagh@digi.lonestar.org> suggests typing some unique string
  292.   like "wxyz", typing the key in question, then typing "C-h l".  The
  293.   characters that appear between "wxyz" and "C-h l" were generated by the
  294.   key.
  295.   
  296. 130: How do I set the X key "translations" for Emacs?
  297.   
  298.   Sorry, you can't; there are no "translations" to be set.  Emacs is not
  299.   written using the Xt library.  The only way to affect the behavior of keys
  300.   within Emacs is through `xmodmap' (outside Emacs) or `define-key' (inside
  301.   Emacs).
  302.   
  303. 131: How do I handle C-s and C-q being used for flow control?
  304.   
  305.   C-s and C-q are used in the XON/XOFF flow control protocol.  This screws
  306.   up Emacs because it binds these characters to commands.  Also, by default
  307.   Emacs will not honor them as flow control characters and may overwhelm
  308.   output buffers.  Sometimes, intermediate software using XON/XOFF flow
  309.   control will prevent Emacs from ever seeing C-s and C-q.
  310.   
  311.   Possible solutions:
  312.   
  313.   * Disable the use of C-s and C-q for flow control.
  314.   
  315.     You need to determine what is the cause of the flow control.
  316.   
  317.     * your terminal
  318.   
  319.       Your terminal may use XON/XOFF flow control to have time to display
  320.       all the characters it receives.  For example, VT series terminals do
  321.       this.  It may be possible to turn this off from a setup menu.  For
  322.       example, on a VT220 you may select `No XOFF' in the setup menu.  This
  323.       is also true for some terminal emulation programs on PCs.
  324.   
  325.       When you turn off flow control at the terminal, you will also need to
  326.       turn it off at the other end, which might be at the computer you are
  327.       logged in to or at some terminal server in between.
  328.   
  329.       If you turn off flow control, characters may be lost; using a printer
  330.       connected to the terminal may fail.  You may be able to get around
  331.       this problem by modifying the `termcap' entry for your terminal to
  332.       include extra NUL padding characters. 
  333.   
  334.     * a modem
  335.   
  336.       If you are using a dialup connection, the modems may be using XON/XOFF
  337.       flow control.  I don't know how to get around this.
  338.   
  339.     * a router or terminal server
  340.   
  341.       Some network box between the terminal and your computer may be using
  342.       XON/XOFF flow control.  It may be possible to make it use some other
  343.       kind of flow control.  You will probably have to ask your local
  344.       network experts for help with this.
  345.   
  346.     * tty and/or pty devices
  347.   
  348.       If your connection to Emacs goes through multiple tty and/or pty
  349.       devices, they may be using XON/XOFF flow control even when it is not
  350.       necessary.
  351.   
  352.       Eirik Fuller <eirik@theory.tn.cornell.edu> writes:
  353.   
  354.         Some versions of `rlogin' (and possibly telnet) do not pass flow
  355.         control characters to the remote system to which they connect.  On
  356.         such systems, Emacs on the remote system cannot disable flow control
  357.         on the local system.  Sometimes `rlogin -8' will avoid this problem.
  358.   
  359.         One way to cure this is to disable flow control on the local host
  360.         (the one running rlogin, not the one running rlogind) using the stty
  361.         command, before starting the rlogin process.  On many systems, `stty
  362.         start u stop u' will do this.
  363.   
  364.         Some versions of `tcsh' will prevent even this from working.  One
  365.         way around this is to start another shell before starting rlogin,
  366.         and issue the stty command to disable flow control from that shell.
  367.   
  368.       Use `stty -ixon' instead of `stty start u stop u' on some systems.
  369.   
  370.   * Make Emacs speak the XON/XOFF flow control protocol.
  371.   
  372.     You can make Emacs treat C-s and C-q as flow control characters by
  373.     evaluating this form:
  374.   
  375.       (set-input-mode nil t)
  376.   
  377.     If you are fixing this for yourself, simply put the form in your .emacs
  378.     file.  If you are fixing this for your entire site, the best place to
  379.     put it is unclear.  I don't know if this has any effect when used in
  380.     lisp/site-init.el when building Emacs; I've never tried that.  {Can
  381.     someone tell me whether it works?}  Putting things in users' .emacs files
  382.     has a number of problems.
  383.   
  384.     Putting this form in lisp/default.el has the problem that if the user's
  385.     .emacs file has an error, this will prevent lisp/default.el from being
  386.     loaded and Emacs may be unusable for the user, even for correcting their
  387.     .emacs file (unless they're smart enough to move it to another name).  A
  388.     possible solution is to initially disable C-s and C-q by setting
  389.     keyboard-translate-table in lisp/site-init.el, either with swap-keys
  390.     (see question 136) or with the following form:
  391.   
  392.       ;; by Roger Crew <crew@cs.stanford.edu>:
  393.       (setq keyboard-translate-table
  394.             "\C-@\C-a\C-b\C-c\C-d\C-e\C-f\C-g\C-h\C-i\C-j\C-k\C-l\C-m\C-n\C-o\C-p\C-^\C-r\C-\\\C-t\C-u\C-v\C-w\C-x\C-y\C-z\C-[\C-s\C-]\C-q\C-_")
  395.   
  396.     This will at least prevent Emacs from being confused by the flow control
  397.     characters, even if lisp/default.el cannot be loaded.  Then, in
  398.     lisp/default.el, enable XON/XOFF flow control with set-input-mode.
  399.   
  400.   For further discussion of this issue, read the file PROBLEMS in the
  401.   Emacs distribution.
  402.   
  403. 132: How do I use commands bound to C-s and C-q (or any key) if these keys
  404.  are filtered out?
  405.   
  406.   I suggest swapping C-s with C-\ and C-q with C-^:
  407.   
  408.     (swap-keys ?\C-s ?\C-\\)
  409.     (swap-keys ?\C-q ?\C-^)
  410.   
  411.   See question 136 for the implementation of swap-keys.  This method
  412.   has the advantage that it simultaneously swaps the characters everywhere
  413.   throughout Emacs, while just switching the keybindings will miss important
  414.   places where the character codes are stored (eg., the search-repeat-char
  415.   variable, major mode keymaps, etc.).
  416.   
  417.   To do this for an entire site, you may want to swap the keys in
  418.   lisp/default.el.  If only some of your users are connecting through
  419.   XON/XOFF flow-controlled connections, you will want to do this
  420.   conditionally.  I suggest pre-swapping them in lisp/site-init.el when
  421.   Emacs is built, and then in lisp/default.el, if it is determined to be
  422.   safe, they can be reenabled (being careful not to screw up any other key
  423.   mappings users might have established using keyboard-translate-table).
  424.   See question 131 for an easy way to pre-swap these keys.
  425.   
  426.   WARNING: If you do this for an entire site, the users will be confused by
  427.   the disparity between what the documentation says and how Emacs actually
  428.   behaves.
  429.   
  430. 133: Why does the `BackSpace' key invoke help?
  431.   
  432.   The BackSpace key (on every keyboard I've used) generates ASCII code 8.
  433.   C-h sends the same code.  In Emacs by default C-h invokes help-command.
  434.   This is intended to be easy to remember since the first letter of "help"
  435.   is "h".  The easiest solution to this problem is to use C-h (and
  436.   BackSpace) for help and DEL (the Delete key) for deleting the previous
  437.   character.
  438.   
  439.   For many people this solution may be problematic:
  440.   
  441.   * They normally use BackSpace outside of Emacs for deleting the previous
  442.     character typed.  This can be solved by making DEL be the command for
  443.     deleting the previous character outside of Emacs.  This command will do
  444.     this on many Unix systems:
  445.   
  446.       stty erase '^?'
  447.   
  448.   * The person may prefer using the BackSpace key for deleting the previous
  449.     character because it is more conveniently located on their keyboard or
  450.     because they don't even have a separate Delete key.  In this case, the
  451.     BackSpace key should be made to behave like Delete.  There are several
  452.     methods.
  453.   
  454.     * Under X Windows, the easiest solution is to change the BackSpace key
  455.       into a Delete key like this:
  456.   
  457.         xmodmap -e "keysym BackSpace = Delete"
  458.   
  459.     * Some terminals (eg., VT3## terminals) allow the character generated by
  460.       the BackSpace key to be changed from a setup menu.
  461.   
  462.     * You may be able to get a keyboard that is completely programmable.
  463.   
  464.     * Under X or on a dumb terminal, it is possible to swap the BackSpace
  465.       and Delete keys inside Emacs:
  466.   
  467.         (swap-keys ?\C-h ?\C-?)
  468.   
  469.       See question 136 for the implementation of swap-keys.
  470.   
  471.     * Another approach is to switch keybindings and put help on "C-x h"
  472.       instead:
  473.   
  474.         (global-set-key "\C-h" 'delete-backward-char)
  475.         (global-set-key "\C-xh" 'help-command) ; override mark-whole-buffer
  476.   
  477.       Other popular key bindings for help are M-? and "C-x ?".
  478.   
  479.       WARNING: Don't try to bind DEL to help-command, because there are many
  480.       modes that have local bindings of DEL that will interfere.             -
  481.   
  482. 134: Why doesn't Emacs look at the stty settings for Backspace vs. Delete?
  483.   
  484.   Good question!
  485.   
  486. 135: Why don't the arrow keys work?
  487.   
  488.   When Emacs starts up, it doesn't know anything about arrow keys at all
  489.   (except when running under X, see question 128).  During the process of
  490.   starting up, Emacs will load a terminal-specific initialization file for
  491.   your terminal type (as determined by the environment variable TERM), if
  492.   one exists.  This file has the responsibility for enabling the arrow keys.
  493.   
  494.   There are several things that can go wrong:
  495.   
  496.   1. There is no initialization file for your terminal.
  497.   
  498.      You can determine this by looking in the lisp/term directory.  If your
  499.      terminal type (as determined by the TERM environment variable) is
  500.      xxx-yy-z, then the first of these files in the lisp/term directory will
  501.      be loaded as the terminal-specific initialization file: xxx-yy-z.el,
  502.      xxx-yy.el, or xxx.el.
  503.   
  504.      There are two major cases of this problem:
  505.   
  506.      * Your terminal type is very similar to one that has an init file.
  507.   
  508.        In this case, there are several techniques suggested by Colin Jensen
  509.        <cjensen@ampex.com>, Ben Liblit <Liblit@cs.psu.edu>, and Marc
  510.        Auslander <marc@watson.ibm.com>:
  511.   
  512.        A. Add a symbolic link in lisp/term for your terminal type that
  513.           points to the similar type.  For example, you could make VT102
  514.           terminals work with this command:
  515.   
  516.             ln -s vt100.el vt102.el
  517.   
  518.           This fixes things for everyone on the system who uses the terminal
  519.           type.
  520.   
  521.        B. If you can't do the solution in part A, you can add code to your
  522.           term-setup-hook that loads the correct file like this:
  523.   
  524.             (setq term-setup-hook
  525.                   (function
  526.                    (lambda ()
  527.                      (cond ((equal "vt102" (or (getenv "TERM") ""))
  528.                             (load (concat term-file-prefix "vt100")))
  529.                            (;; Code for other terminal types goes here ...
  530.                             )))))
  531.   
  532.        C. If you use `tset' to set your TERM environment variable when you
  533.           login, you can use the `-m' switch to tell tset to use a terminal
  534.           type known by Emacs instead of another similar one.  For example,
  535.           specifying this:
  536.   
  537.             tset ... -m 'dec-vt220:vt220' ...
  538.   
  539.           will make tset say you are on a `vt220' instead of a `dec-vt220'.
  540.   
  541.        D. Interactively, you can type "M-x load-library RET term/vt100" to
  542.           load the terminal-specific initialization files for VT100
  543.           terminals.
  544.   
  545.      * Your terminal type is not similar to one that has an init file.
  546.   
  547.        One can be made for your terminal, or you can just add code to your
  548.        own .emacs to handle this problem for yourself.  For example, if your
  549.        terminal's arrow keys send these character sequences:
  550.   
  551.          Up:    ESC [ A
  552.          Down:  ESC [ B
  553.          Right: ESC [ C
  554.          Left:  ESC [ D
  555.   
  556.        then you can bind these keys to the appropriate commands with code in
  557.        your .emacs like this:
  558.   
  559.          (setq term-setup-hook
  560.                (function
  561.                 (lambda ()
  562.                   (cond ((string-match "\\`xyzzy" (or (getenv "TERM") ""))
  563.                          ;; First, must unmap the binding for left bracket
  564.                          (or (keymapp (lookup-key global-map "\e\["))
  565.                              (define-key global-map "\e\[" nil))
  566.                          ;; Enable terminal type xyzzy's arrow keys:
  567.                          (define-key global-map "\e\[A" 'previous-line)
  568.                          (define-key global-map "\e\[B" 'next-line)
  569.                          (define-key global-map "\e\[C" 'forward-char)
  570.                          (define-key global-map "\e\[D" 'backward-char))
  571.                         ((string-match "\\`abcde" (or (getenv "TERM") ""))
  572.                          ;; Do something different for terminal type abcde
  573.                          ;; .....
  574.                          )))))
  575.   
  576.      NOTE: You may have to restart Emacs to get changes to take effect.
  577.   
  578.      NOTE: Your arrow keys may send sequences beginning with "ESC O" when
  579.      Emacs is running, even if they send sequences beginning with "ESC [" at
  580.      all other times.  This is because Emacs uses any command there may be
  581.      in your terminal's termcap entry for putting the terminal into
  582.      "Application Keypad Mode".  Just map these sequences the same way as
  583.      above.
  584.   
  585.   The next two cases are problems even if there is a initialization file for
  586.   your terminal type.
  587.   
  588.   2. The initialization file for your terminal doesn't bind arrow keys.
  589.   
  590.      If your terminal type is `xterm', you will have to bind the arrow keys
  591.      as in part 1 above, since the xterm.el file doesn't do anything useful.
  592.      There may be other terminal types with the same problem.
  593.   
  594.   3. Your terminal's arrow keys send individual control characters.
  595.   
  596.      For example, the arrow keys on an ADM-3 send C-h, C-j, C-k, and C-l.
  597.   
  598.      There is not much Emacs can do in this situation, since all the control
  599.      characters except for C-^ and C-\ are already used as Emacs commands.
  600.      It may be possible to convince the terminal to send something else when
  601.      you press the arrow keys; it is worth investigating.
  602.   
  603.      You have to make the hard choices of how to rebind keys to commands to
  604.      make things work the way you want.  Another alternative is to start
  605.      learning the standard Emacs keybindings for moving point around: C-b,
  606.      C-f, C-p, and C-n.  Personally, I no longer use the arrow keys when
  607.      editing because I have switched keyboards so many times.
  608.   
  609.   4. Your terminal's arrow keys send sequences beginning with "ESC [".
  610.   
  611.      Due to an extremely poor design decision (ie., these sequences are ANSI
  612.      standard), none of the the terminal-specific initialization files that
  613.      are distributed with Emacs will bind these character sequences to the
  614.      appropriate commands by default.  (This also applies to any other
  615.      function keys which generate character sequences starting with "ESC
  616.      [".)  This is because it was deemed far more important to preserve the
  617.      binding of M-[ to the backward-paragraph command.  It appears that this
  618.      will change in Emacs 19.
  619.   
  620.      Some of the terminal-specific initialization files that come with Emacs
  621.      provide a command enable-arrow-keys that will fix this problem.  To get
  622.      this automatically invoked, put this in your .emacs:
  623.   
  624.        (setq term-setup-hook
  625.          (function
  626.           (lambda ()
  627.         (if (fboundp 'enable-arrow-keys) (enable-arrow-keys)))))
  628.   
  629.      We put this in our lisp/default.el file, so users don't have to worry
  630.      about it:
  631.   
  632.        ;; don't override a user's term-setup-hook
  633.        (or term-setup-hook
  634.        (setq term-setup-hook
  635.          (function
  636.           (lambda ()
  637.             (and (fboundp 'enable-arrow-keys)
  638.              ;; don't override a user key mapping
  639.              (eq 'backward-paragraph (lookup-key esc-map "["))
  640.              (enable-arrow-keys))))))
  641.   
  642.      If your terminal type is `sun', you should put this in your .emacs
  643.      instead (or in addition to the above):
  644.   
  645.        (setq sun-esc-bracket t)
  646.   
  647.      It is possible that the terminal-specific initialization file for your
  648.      terminal type was written locally and does not follow the rule
  649.      mentioned above.  In this case you may need to inspect it to find out
  650.      how to enable the arrow keys.  (Actually, if it was written locally, it
  651.      probably enables the arrow keys by default.)
  652.   
  653. 136: How do I "swap" two keys?
  654.   
  655.   When Emacs receives a character, you can make Emacs behave as though it
  656.   received another character by setting the value of
  657.   keyboard-translate-table.  The following Emacs Lisp will do this for you,
  658.   allowing you to "swap" keys.  After arranging for this Lisp to be
  659.   evaluated by Emacs, you can evaluate `(swap-keys ?A ?B)' to swap A and B.
  660.   
  661.     (defun swap-keys (key1 key2)
  662.       "Swap keys KEY1 and KEY2 using map-key."
  663.       (map-key key1 key2)
  664.       (map-key key2 key1))
  665.   
  666.     (defun map-key (from to)
  667.       "Make key FROM behave as though key TO was typed instead."
  668.       (setq keyboard-translate-table
  669.         (concat keyboard-translate-table
  670.             (let* ((i (length keyboard-translate-table))
  671.                (j from)
  672.                (k i)
  673.                (str (make-string (max 0 (- j (1- i))) ?X)))
  674.               (while (<= k j)
  675.             (aset str (- k i) k)
  676.             (setq k (1+ k)))
  677.               str)))
  678.       (aset keyboard-translate-table from to)
  679.       (let ((i (1- (length keyboard-translate-table))))
  680.     (while (and (>= i 0) (eq (aref keyboard-translate-table i) i))
  681.       (setq i (1- i)))
  682.     (setq keyboard-translate-table
  683.           (if (eq i -1)
  684.           nil
  685.         (substring keyboard-translate-table 0 (1+ i))))))
  686.   
  687.   NOTE: You must evaluate the definition of these functions before calling
  688.   them!  For example, list the function definitions before their use in your
  689.   .emacs file.
  690.   
  691.   NOTE: These functions take two numbers as arguments.  The example above,
  692.   `(swap-keys ?A ?B)' is actually `(swap-keys 65 66)', because `?A' is
  693.   merely notation for 65, the ASCII value of `A'.
  694.   
  695.   NOTE: These functions only work for single characters.  You cannot swap
  696.   two multi-character sequences.
  697.   
  698. 137: How do I produce C-XXX with my keyboard?
  699.   
  700.   For C-@ and C-^, often you can just type Control-2 and Control-6.  For
  701.   C-_, you may have to hold down the shift key, typing Control-Shift-Hyphen.
  702.   C-@ can often be generated by typing Control-Space.  C-@ is often called
  703.   the NUL character, and has ASCII value 0.  C-_ can often be generated by
  704.   typing Control-7 or Control-/.  C-? (aka DEL) may be generated by typing
  705.   Shift-BackSpace or Control-BackSpace or a key labelled Delete or Del.
  706.   
  707.   Try Control with all of the digits on your keyboard to see what gets
  708.   generated.
  709.   
  710. 138: What if I don't have a Meta key?
  711.   
  712.   Instead of typing M-a, you can type "ESC a" instead.  In fact, Emacs
  713.   converts M-a internally into "ESC a" anyway (depending on the value of
  714.   meta-prefix-char).
  715.   
  716. 139: What if I don't have an Escape key?
  717.   
  718.   Type C-[ instead.  This should send ASCII code 27 just like an Escape
  719.   key would.  Try also C-;.
  720.   
  721. 140: How do I type DEL on PC terminal emulators?
  722.   
  723.   Some IBM PC compatibles do not have a key labeled `Del' or `Delete' {is
  724.   this true?}.  Those that do generally have it in an inconvenient location.
  725.   (Also, in some terminal emulators, the `Del' key does not transmit DEL.)
  726.   The result is the standard "BackSpace invoking help" problem (see question
  727.   133).
  728.   
  729.   The usual solution, suggested by Michael Covington
  730.   <mcovingt@aisun1.ai.uga.edu>, is to somehow tell the terminal emulator
  731.   program that BackSpace should transmit DEL.  Read the program's manual.
  732.   Shift-BackSpace or Control-BackSpace may send DEL.  The `Del' key may only
  733.   send DEL if the NumLock key hasn't been pressed.
  734.   
  735. 141: Can I make my `Compose Character' key behave like a Meta key?
  736.   
  737.   On a dumb terminal such as a VT220, no.  It is rumored that certain VT220
  738.   clones could have their Compose key configured this way.  If you're using
  739.   X, you might be able to do this with the `xmodmap' program (this is
  740.   what I do).
  741.   
  742. 142: How do I bind a combination of modifier key and function key?
  743.   
  744.   Unless you're using Emacs under emacstool (or xvetool?), have a working    !
  745.   version of x-rebind-key (see question 128), or are using Emacs 19 (Lucid   +
  746.   Emacs), you can't do this with Emacs alone.                                +
  747.   
  748.   If you are using emacstool, Emacs sees different character sequences for
  749.   the combination of a modifier and a function key from what it sees for the
  750.   function key alone.  See etc/emacstool.1 for more information.  Since
  751.   Emacs sees different character sequences, you can bind these different
  752.   sequences to different commands.
  753.   
  754.   If you are running Emacs inside a terminal emulator window like xterm, you
  755.   can modify its translation tables to make it generate different character
  756.   sequences for the combination of a modifier and a function key.  For
  757.   example, this X resource setting:
  758.   
  759.     XTerm.VT100.Translations: #override \
  760.       Shift<KeyPress>F1: string(0x1b) string("[xyzzy")
  761.   
  762.   makes Shift-F1 generate the character sequence "ESC [ xyzzy".  You can
  763.   bind these character sequences in Emacs as normal.  Nick Ruprecht
  764.   <ruprecht@informatik.uni-freiburg.de> has written an extensive X
  765.   translation mapping for xterm that does this.  {Does this have an FTP
  766.   site?}
  767.   
  768.   If you have x-rebind-key, you can have any arbitrary combination of        +
  769.   modifiers with a key replaced by any sequence of "normal" characters.  For +
  770.   example, this makes Shift-Return behave as though you had typed "C-x C-e"  +
  771.   (example from Jerry Graves):                                               +
  772.                                                                              +
  773.     (x-rebind-key "Return" 'shift "\C-x\C-e")                                +
  774.                                                                              +
  775.   In Emacs 19 (Lucid Emacs), you can bind Meta-Left-Arrow like this (example +
  776.   from Jamie Zawinski):                                                      +
  777.                                                                              +
  778.     (global-set-key '(meta left) 'backward-word)                             +
  779.                                                                              +
  780.   With the last two methods, use `xmodmap' and `xev' to discover the keysym  +
  781.   and modifier names.                                                        +
  782.   
  783. 143: Why doesn't my Meta key work in an xterm window?
  784.   
  785.   Try all of these methods before asking for further help:
  786.   
  787.   * You may have big problems using `mwm' as your window manager.  {Does
  788.     anyone know a good generic solution to allow the use of the Meta key in
  789.     Emacs with mwm?}
  790.   
  791.   * For X11R4: Make sure it really is a Meta key.  Use `xev' to find out
  792.     what keysym your Meta key generates.  It should be either Meta_L or
  793.     Meta_R.  If it isn't, use xmodmap to fix the situation.
  794.   
  795.   * Make sure the pty the xterm is using is passing 8 bit characters.
  796.     `stty -a' (or `stty everything') should show `cs8' somewhere.  If it
  797.     shows `cs7' instead, use `stty cs8 -istrip' (or `stty pass8') to fix
  798.     it.
  799.   
  800.   * If there is an rlogin connection between the xterm and the Emacs, the
  801.     `-8' argument may need to be given to rlogin to make it pass all 8
  802.     bits of every character.
  803.   
  804.   * If the Emacs is running under Ultrix, it is reported that evaluating
  805.     (set-input-mode t nil) helps.
  806.   
  807.   * If all else fails, you can make xterm generate "ESC W" when you type
  808.     M-W, which is the same conversion Emacs would make if it got the M-W
  809.     anyway.  In X11R4, the following resource specification will do this:
  810.   
  811.       XTerm.VT100.EightBitInput: false
  812.   
  813.     (This changes the behavior of the insert-eight-bit action.)
  814.   
  815.     With older xterms, you can specify this behavior with a translation:
  816.   
  817.       XTerm.VT100.Translations: #override \
  818.         Meta<KeyPress>: string(0x1b) insert()
  819.   
  820.     You might have to replace `Meta' with `Alt'.
  821.   
  822. 144: Why doesn't my ExtendChar key work as a Meta key under HP-UX 8.0?
  823.   
  824.   This is a result of an internationalization extension in X11R4 and the
  825.   fact that HP is now using this extension.  Emacs assumes that
  826.   XLookupString returns the same result regardless of the Meta key state
  827.   which is no longer necessarily true.  Until Emacs is fixed, the temporary
  828.   kludge is to run this command after each time the X server is started but
  829.   preferably before any xterm clients are:
  830.   
  831.     xmodmap -e 'remove mod1 = Mode_switch'
  832.   
  833.   NOTE:  This will disable the use of the extra keysyms systemwide, which
  834.   may be undesirable if you actually intend to use them.
  835.   
  836. 145: Where can I get key bindings to make Emacs emulate WordStar?
  837.   
  838.   There is a package `wordstar' by Jim Frost <jimf@saber.com> and
  839.   `ws-mode.el' by Juergen Nickelsen <nickel@cs.tu-berlin.de>.  Check in the
  840.   Emacs Lisp Archive (see question 89).
  841.   
  842. 146: Where can I get an XEDIT emulator for Emacs?
  843.   
  844.   This question comes up once every couple of months.  I have never seen a
  845.   positive reply, so I presume no one has ever written one.
  846.   
  847.  
  848.  
  849. Using Emacs with Alternate Character Sets
  850.  
  851. 147: How do I make Emacs display 8-bit characters?
  852.   
  853.   There is a patch called the `8-bit ctl-arrow patch' that allows Emacs to
  854.   display characters with codes from 128 to 255.  {The original appears to
  855.   have been by Kenneth Cline <cline@proof.ergo.cs.cmu.edu>.} Partially based
  856.   on Johan Widen's earlier work, Johan Vromans <jv@mh.nl> has updated this
  857.   patch for Emacs 18.58 along with some other 8-bit improvements.
  858.   
  859.   Anonymous FTP:
  860.     /ftp.eu.net:gnu/emacs/FP-EightBit.Z                                      +
  861.     /ftp.urc.tue.nl:pub/tex/emacs/FP-EightBit                                +
  862.     /cs.purdue.edu:pub/ygz/cemacs.tar.Z:cemacs/8bit-patch-18.57              +
  863.     /sics.se:archive/emacs-18.55-8bit-diff                                   +
  864.     /laas.laas.fr:pub/emacs/patch-8bit-18.55                                 !
  865.     /laas.laas.fr:pub/emacs/patch-8bit-18.57                                 !
  866.   
  867.   Via e-mail:
  868.     To: mail-server@sics.se
  869.     body: send emacs-18.55-8bit-diff
  870.   
  871.   Anders Edenbrandt <anderse@dna.lth.se> has produced a more comprehensive
  872.   patch for Emacs 18.57 that allows for 8-bit input and output.
  873.   
  874.   Anonymous FTP:
  875.     /sics.se:archive/emacs-8bit-diff-lth                                     +
  876.     /gatekeeper.dec.com:pub/GNU/DS-emacs-18.57-8bit-diff-lth                 +
  877.   
  878.   The most comprehensive patches for 8-bit output are by Howard Gayle
  879.   (originally for Emacs 18.55.  These patches allow displaying any arbitrary
  880.   string for a given 8-bit character (except TAB and C-j).  Also supported
  881.   is defining the sorting order and the uppercase and lowercase
  882.   translations.  It is reported that the 8-bit character support in Emacs 19
  883.   is largely based on these patches.  Thomas Bellman
  884.   <Bellman@lysator.liu.se> has updated these patches for Emacs 18.57.
  885.   
  886.   Anonymous FTP:
  887.     /sics.se:archive/emacs-gayle.tar.Z  (patches for 18.55)                  +
  888.     /ftp.lysator.liu.se:pub/emacs/gayle-18.57.diff.tar.Z  (patches)          +
  889.     /ftp.lysator.liu.se:pub/emacs/emacs-18.57-gayle.tar.Z  (patched Emacs)   +
  890.   
  891.   I am not sure if Epoch can display 8-bit characters as is.  Lucid Emacs
  892.   has the ctl-arrow patch installed.  Nemacs displays 8-bit characters, and
  893.   it may be useful for displaying the 8-bit ISO-8859 alphabet, but I don't
  894.   know for sure (see question 149).
  895.   
  896. 148: How do I input 8-bit characters?
  897.   
  898.   Minor modes for ISO Latin-1 that allow one to easily input this character
  899.   set have been written by several people.  Such modes have been written by
  900.   Matthieu Herrb <matthieu@laas.fr> (laas.laas.fr:pub/emacs/iso-latin-1.el),
  901.   Johan Vromans <jv@mh.nl> {FTP site??}, and Marc Shapiro
  902.   <shapiro@sor.inria.fr> {FTP site??}.
  903.   
  904.   These approaches differ from the one taken by Anders Edenbrandt in that
  905.   his method uses direct 8-bit input, while these methods use a compose
  906.   sequence for 8-bit characters.  {I have heard conflicting reports on
  907.   whether this results in losing the Meta key.  Perhaps this depends on
  908.   whether Emacs is running under X.  Can someone resolve this?}
  909.   
  910.   Karl Heuer <karl@haddock.ima.isc.com> is said to have a patch to allow
  911.   8-bit input.  Georg-Wilhelm Koltermann <gwk@crmunich0.cray.com> also has a
  912.   patch for either 18.57 or 18.58 that allows 8-bit input.
  913.   
  914.   Epoch comes with a patch that allows it to input 8-bit characters, but it
  915.   is not enabled by default.  {Is this right?}
  916.   
  917.   Jamie Zawinski says:                                                       +
  918.                                                                              +
  919.     Lucid GNU Emacs allows the input of any ISO-8859/1 keysyms that your     +
  920.     keyboard generates (see xmodmap), and contains a package that implements +
  921.     a DEC/OpenWindows-like "Compose" key for systems which don't have one.   +
  922.   
  923. 149: Where can I get an Emacs that can handle kanji characters?
  924.   
  925.   Nemacs 3.3.2 (Nihongo GNU Emacs) is a modified version of GNU Emacs 18.55
  926.   that handles kanji characters.  It is available via anonymous FTP:         !
  927.                                                                              !
  928.     /crl.nmsu.edu:pub/misc/nemacs-3.3.2.tar.Z                                !
  929.     /uhccux.uhcc.hawaii.edu:editors/Nemacs-3.3.2/                            !
  930.     /miki.cs.titech.ac.jp:JAPAN/nemacs/nemacs-3.3.2.tar.Z                    !
  931.   
  932.   You might also need files for "wnn", a kanji input method
  933.   (wnn-4.0.3{-README,.tar.Z} {on which machine?}).  You need a terminal (or
  934.   terminal emulator) that can display text encoded in JIS, Shift-JIS, or EUC
  935.   (Extended Unix Code), or the ability to run Nemacs as a direct X Window
  936.   client.
  937.   
  938. 150: Where can I get an Emacs that can handle Chinese?
  939.   
  940.   `cemacs' by Stephen G. Simpson <simpson@math.psu.edu> is a patch to Emacs
  941.   18.57 (the ctl-arrow patch) and some Emacs Lisp code that combined with
  942.   Cxterm allows using Chinese characters.  It is available via anonymous
  943.   FTP:                                                                       !
  944.                                                                              !
  945.     /crl.nmsu.edu:pub/chinese/cemacs.tar.Z                                   !
  946.     /cs.purdue.edu:pub/ygz/cemacs.tar.Z                                      !
  947.   
  948.   Cxterm is available from the same place:                                   !
  949.                                                                              !
  950.     /cs.purdue.edu:pub/ygz/cxterm-11.5.1.tar.Z                               !
  951.   
  952. 151: Where is an Emacs that can handle Semitic (right-to-left) alphabets?
  953.   
  954.   Joel M. Hoffman <joel@wam.umd.edu> writes:
  955.   
  956.     A couple of years ago a wrote a hebrew.el file that allows right-to-left
  957.     editing of Hebrew.  I relied on the hardware to display the Hebrew
  958.     letters, given the right codes, but not for any right-to-left support;
  959.     the hardware also doesn't have to send any specific char. codes.  Emacs
  960.     keeps track of when the user is typing Hebrew vs. English.  (The VT-*
  961.     terminals in Israel contain built-in support for Hebrew.)
  962.   
  963.     To get it to work I had to modify only a few lines of GNU Emacs's source
  964.     code --- just enough to make it 8-bit clean.
  965.   
  966.     [and in a separate message:]
  967.   
  968.     It doesn't produce time-order ["sefer" format] (I wouldn't recommend
  969.     trying that with emacs, because converting time-order to screen-order
  970.     with arbitrarily long lines is a bit tricky), but I also concocted a
  971.     quick filter to convert screen-order into time-order.  I'll be happy to
  972.     send you the requisite files if you want them.  If you're using it for
  973.     anything large, however, you'll want something that works better.
  974.   
  975.   Joel Hoffman has also written a "bi-directional bi-lingual Emacs-like"
  976.   editor for MS-DOS named Ibelbe (Itty Bitty Emacs-Like Bidirectional
  977.   Editor).  Ibelbe is written in Turbo Pascal and comes with source code.
  978.   Here is the description:
  979.   
  980.     Ibelbe looks like emacs (it even has a minibuffer and filename
  981.     completion), and fully supports both right-to-left and left-to-right
  982.     editing.  Other than an EGA monitor or better, no special hardware is
  983.     required.  You will need an EGA Hebrew font to use Ibelbe with Hebrew.
  984.   
  985.   Anonymous FTP:
  986.     /israel.nysernet.org:israel/msdos/ibelbe.zip                             !
  987.     /israel.nysernet.org:israel/msdos/hebfont.zip                            !
  988.   
  989.   Joseph Friedman <yossi@deshaw.com, yossi@Neon.Stanford.EDU> has written
  990.   patches for Emacs 18.55 and 18.58 that provide Semitic language support
  991.   under X Windows.
  992.   
  993.   Warren Burstein <warren@itex.jct.ac.il> says he has mapped 7-bit keys by
  994.   modifying self-insert-command "for Hebrew input on 7-bit keyboards".
  995.   
  996.   A good suggestion is to query archie for files named with `hebrew'.
  997.   
  998.